﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using VietTrips.Domain.Contexts;
using VietTrips.Domain.Helpers;
using VietTrips.Domain.Interfaces;
using VietTrips.Domain.Models;
using VietTrips.Domain.Repositories;

namespace VietTrips.Domain.Services
{
    public class AdvancedSearchService
    {
        private readonly ITripRepository _tripRepository = new TripRepository();

        private IEnumerable<ResultSearch> GetUsersInOrdered(string orderedBy = "Tripid",
           IEnumerable<ResultSearch> input = null)
        {
            if (input == null)
            {
                return null;
            }
            switch (orderedBy)
            {
                case "Price":
                    return input.OrderBy(profile => profile.PriceAdult);
                case "TourName":
                    return input.OrderBy(profile => profile.TourName);
                case "StarOfTour":
                    return input.OrderBy(profile => profile.StarOfTour);
                case "Username_desc":
                    return input.OrderByDescending(profile => profile.TripId);
                case "TourName_desc":
                    return input.OrderByDescending(profile => profile.TourName);
                case "Price_desc":
                    return input.OrderByDescending(profile => profile.PriceAdult);
                case "StarOfTour_desc":
                    return input.OrderByDescending(profile => profile.StarOfTour);
                default:
                    return input.OrderBy(profile => profile.TripId);
            }
        }

        public List<ResultSearch> AdvanceSearch(string orderedBy, Search searchInfo)
        {
            var result = _tripRepository.SearchByValues(searchInfo);
            return GetUsersInOrdered(orderedBy, result).ToList();
        }
    }
}
